const app = getApp()
const $ = app.globalData
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		page: 1
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		var shopid = options.id
		var that = this
		wx.request({
			url: $.AdminUrl + "/YApi/getShopIndex",
			data: {
				shopid: shopid
			},
			success: function(data) {
				console.log(data)
				var loadmore = false
				if (data.data.obj.goodsList.length >= 10) {
					loadmore = true
				} else {
					loadmore = false
				}
				that.setData({
					shopid: shopid,
					loadmore: loadmore,
					hotList: data.data.obj.hotList,
					allgoods: data.data.obj.goodsList,
					shopinfo: data.data.obj.shop
				})
			}
		})
	},
	// 加载更多
	loadgengduo: function() {
		var that = this
		var page = that.data.page + 1
		wx.request({
			url: $.AdminUrl + "/YApi/getShopPage",
			data: {
				page: page,
				shopid: that.data.shopid,
				name: ""
			},
			success: function(res) {
				console.log(res)
				var loadmore = false
				var allgoods = that.data.allgoods
				if (res.data.obj.length >= 10) {
					loadmore = true
				} else {
					loadmore = false
				}
				allgoods = allgoods.concat(res.data.obj)
				that.setData({
					page: page,
					allgoods: allgoods,
					loadmore: loadmore
				})

			}

		})
	},
	clickGoods: function(e) {
		var that = this
		var goodsId = e.currentTarget.dataset.id
		var shopid = that.data.shopid
		var shopname = that.data.shopinfo.name
		
		wx.navigateTo({
			url: "../details/details?id=" + goodsId + "&shopid=" + shopid + "&shopname="+shopname
		})
		// var thisid = e.currentTarget.dataset.id
		// wx.navigateTo({
		// 	url: "/pages/shopping/business/business?id=" + thisid
		// })
	},
	pingtaigoods: function(e) {
		var that = this
		var thisid = e.currentTarget.dataset.id
		wx.navigateTo({
			url: "/pages/shopping/details/details?id=" + thisid + "&goodslib=0&daizhuce=" + that.data.daizhuce
		})
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},
	// 分享转发
		onShareAppMessage: function() {
			var userinfo = wx.getStorageSync('userinfo')
			var that = this
			return {
				title: '优悦购生活管家',
				path: '/pages/shopping/shop/shop?userid='+userinfo.loginname+"&id="+that.data.shopid,
				success: (res) => {
					console.log("转发成功", res);
				},
				fail: (res) => {
					console.log("转发失败", res);
				}
			}
		}
})
